//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================
#ifndef __REPLY_H__
#define __REPLY_H__

#include <protocol.h>
#include <aura.h>

EXTERN_C void * __cdecl memcpy(void * pDest, const void * pSource, size_t cb);

// get the request vararg data
inline static const void *get_req_data(void* req_ptr, unsigned int index)
{
    struct central_request_info *info = (struct central_request_info *)req_ptr;

    if (index < info->request_data_count)
        return info->request_data[index].ptr;
    return NULL;
}

// get the request vararg size
inline static size_t get_req_data_size(void* req_ptr, unsigned int index)
{
    struct central_request_info *info = (struct central_request_info *)req_ptr;

    if (index < info->request_data_count)
        return info->request_data[index].size;
    return 0;
}

/* allocate and fill the reply data */
inline static int set_reply_data(void *req_ptr, unsigned int index, const void *ptr, unsigned int size)
{
    struct central_request_info * info = (struct central_request_info *)req_ptr;

    info->reply_data[index].ptr = (void *)ptr;
    info->reply_data[index].size = size;

    return 0;
}

typedef int(*req_handler)(void *request, void *reply);

#define DECL_HANDLER(name) \
    int req_##name(struct name##_request *req, struct name##_reply *reply)

#define REQUEST_ENTRY(x) DECL_HANDLER(x);
REQUEST_TABLE
#undef REQUEST_ENTRY

EXTERN_C ECode central_request_loop(void);

#endif /*__REPLY_H__*/
